package com.feeyin.radar.msg.dao.impl;

import com.feeyin.radar.msg.dao.CommentDAO;
import com.feeyin.radar.msg.model.Comment;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class CommentDAOImpl extends SqlMapClientDaoSupport
  implements CommentDAO
{
  public List getCommentsBymessageId(Integer messageId)
  {
    if (messageId == null) return null;
    return getSqlMapClientTemplate().queryForList("getCommentsBymessageId", messageId);
  }

  public boolean insertComment(Comment comment) {
    if (comment == null) return false;
    Integer result = (Integer)getSqlMapClientTemplate().insert("insertComment", comment);
    return result != null;
  }

  public boolean deleteCommentById(Integer id)
  {
    if (id == null) return false;
    Comment comment = new Comment();
    comment.setId(id);
    Integer result = Integer.valueOf(getSqlMapClientTemplate().delete("deleteCommentByDynamic", comment));
    return result != null;
  }

  public boolean deleteCommentByMessageId(Integer messageId)
  {
    if (messageId == null) return false;
    Comment comment = new Comment();
    comment.setMessageId(messageId);
    Integer result = Integer.valueOf(getSqlMapClientTemplate().delete("deleteCommentByDynamic", comment));
    return result != null;
  }
}